﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace shell
{
    public class ANSI
    {
        public static void ParserANSI(string ansi)
        {
            Match m = new Regex(@"\[(.*)([A-Za-z])").Match(ansi);
            string cmd = m.Groups[2].Value;
            string value = m.Groups[1].Value;
            switch (cmd)
            { 
                case "m":
                    do_parse_m(value);
                    break;
                case "J":
                    if (value == "2")
                    {
                        Console.Clear();
                    }
                    break;
            }


            
        }



        private static void do_parse_m(string str)
        {
            foreach (string cc in str.Split(';'))
            {
                switch (cc)
                {
                    case "0":
                        Console.ResetColor();
                        break;
                    case "1":

                        break;
                    case "30":
                        Console.ForegroundColor = ConsoleColor.Black;
                        break;
                    case "31":
                        Console.ForegroundColor = ConsoleColor.Red;
                        break;
                    case "32":
                        Console.ForegroundColor = ConsoleColor.Green;
                        break;
                    case "33":
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        break;
                    case "34":
                        Console.ForegroundColor = ConsoleColor.Blue;
                        break;
                    case "35":
                        Console.ForegroundColor = ConsoleColor.DarkMagenta;
                        break;
                    case "36":
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        break;
                    case "37":
                        Console.ForegroundColor = ConsoleColor.White;
                        break;
                    case "40":
                        Console.BackgroundColor = ConsoleColor.Black;
                        break;
                    case "41":
                        Console.BackgroundColor = ConsoleColor.Red;
                        break;
                    case "42":
                        Console.BackgroundColor = ConsoleColor.Green;
                        break;
                    case "43":
                        Console.BackgroundColor = ConsoleColor.Yellow;
                        break;
                    case "44":
                        Console.BackgroundColor = ConsoleColor.Blue;
                        break;
                    case "45":
                        Console.BackgroundColor = ConsoleColor.DarkMagenta;
                        break;
                    case "46":
                        Console.BackgroundColor = ConsoleColor.DarkGreen;
                        break;
                    case "47":
                        Console.BackgroundColor = ConsoleColor.White;
                        break;

                }

            }
        }
    }
}
